<?php
namespace App\Models\Agency\Config;

use App\Models\Agency\Model;
use App\Models\Traits\Agency\LogsActivity;
use Helper\Timed;
use Illuminate\Database\Eloquent\SoftDeletes;

class Timezone extends Model
{
    use SoftDeletes, LogsActivity;

    /**
     * 数据表名称
     *
     * @var string
     */
    protected $table = 'config_timezones';

    /**
     * 进行类型转换的字段
     *
     * @var array
     */
    protected $casts = [
        'created' => 'timestamp',
        'updated' => 'timestamp'
    ];

    /**
     * 可以批量赋值的字段
     *
     * @var array
     */
    protected $fillable = [
        'name',
        'code',
        'timezone'
    ];

	public static function getTimeZoneList($where = [], $fields = ['*'], $page = 0, $limit = 100, $orderBy = 'id', $groupBy = '',
		$direction = 'DESC')
	{

		$query = static::query()->where($where)->offset($page)->limit($limit)->orderBy($orderBy, $direction);
		if ($groupBy) {
			$query->groupBy($groupBy);
		}

		return  $query->get(
					is_array($fields) ? $fields : func_get_args()
				);
	}

	public static function getSelectData($where = [], $fields = ['*'], $page = 1, $limit = 20, $orderBy = 'id', $groupBy = '', $direction = 'DESC')
	{
		$res = self::getTimeZoneList($where, $fields, $page, $limit, $orderBy, $groupBy, $direction);
		return $res;
		// return array_column($res->toArray(), null, 'name');
	}
}
